package com.tuanzi.loan.web.bean.family.user;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.constants.DictionaryCode;
import com.tuanzi.loan.business.service.user.LoanUserAgreementService;
import com.tuanzi.loan.vo.request.user.LoanUserAgreementSearchRequest;
import com.tuanzi.loan.vo.response.user.LoanUserAgreementResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.user.LoanUserAgreementLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.util.List;

/**
 * @Author: chenweijun
 * @Date: 2019/9/24 19:25
 */
@Data
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class LoanUserAgreementListBean extends JSFListingBean<LoanUserAgreementSearchRequest, LoanUserAgreementResponse>{

    @Autowired
    private LoanUserAgreementService loanUserAgreementService;

    @PostConstruct
    public void init(){
        initLazyDataModel();
    }

    private void initLazyDataModel(){
        $ = new LoanUserAgreementSearchRequest();
        lazyDataModel = new LoanUserAgreementLazyDataModel($);
    }

    public void onOnline(Long id) {
        loanUserAgreementService.online(id);
        addSuccessfullyMessage();
    }

    public void onOffline(Long id){
        loanUserAgreementService.offline(id);
        addSuccessfullyMessage();
    }

    public void onDelete(Long id){
        loanUserAgreementService.delete(id);
        addSuccessfullyMessage();
    }

    public String onAdd(){
        return redirect("/views/family/user/loan-user-agreement-info.xhtml");
    }

    @Override
    protected List<String> getDictionaryCodes() {
        return Lists.newArrayList(DictionaryCode.LOAN_USER_AGREEMENT_STATUS, DictionaryCode.LARGE_COMMON_PRODUCT);
    }

}
